package com.briup.web.servlet;

import com.briup.bean.Book;
import com.briup.service.IBookService;
import com.briup.service.impl.IBookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/viewBook")
public class ViewBookServlet extends HttpServlet {
    private IBookService bookService = new IBookServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收参数
        Integer id = Integer.parseInt(req.getParameter("id"));
        //2.封装对象
        //3.调用service
        Book book = bookService.findBookById(id);
        //4.根据service返回的结果页面【动态数据el表达jstl】
        req.setAttribute("book",book);
        req.getRequestDispatcher("/viewBook.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}